from flask import Blueprint, render_template, redirect, url_for
from flask import request
from flask import session


# 1.创建蓝图
admin_bp = Blueprint('admin', __name__, url_prefix='/admin')


from . import view


@admin_bp.before_request
def is_admin_user():
    """管理员权限判断"""
    if not request.url.endswith(url_for("admin.admin_login")):
        print(request.url)
        user_id = session.get("user_id")
        is_admin = session.get("is_admin", False)

        if not user_id or not is_admin:
            return redirect(url_for("admin.admin_login"))
